package com.pandacc.dao.fiction.rowmapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;

import com.pandacc.common.SentenceProcessor;
import com.pandacc.pojo.fiction.FictionChaptersDetailsBean;
import com.pandacc.pojo.fiction.FictionDetailsBean;

/**
 * RowMapper implementation for {@link FictionDetailsBean} 
 * Map each record from db table to a new {@link FictionDetailsBean} bean.
 * (or you can try {@link BeanPropertyRowMapper} in spring)
 * @author Administrator
 *
 */
public class FictionChaptersDetailsBeanRowMapper implements RowMapper<FictionChaptersDetailsBean>{

	public FictionChaptersDetailsBean mapRow(ResultSet rs, int rowNum) throws SQLException {
		FictionChaptersDetailsBean chapter = new FictionChaptersDetailsBean();
		SentenceProcessor processor = new SentenceProcessor();
		
		chapter.setFictionId(rs.getInt("FICTION_ID"));
		chapter.setChapterId(rs.getInt("CHAPTER_ID"));
		chapter.setChapterName(rs.getString("CHAPTER_NAME"));
		String content = rs.getString("CONTENT");
		List<String> pargragh = processor.segSentence(content);
		chapter.setContent(pargragh);
		return chapter;
	}

}
